package com.example.labb2da523b.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

class DatabaseHelper extends SQLiteOpenHelper{
	public static final String USER_TABLE_NAME="user";
	public static final String KEY_BUDGET = "budget";

	public static final String EXPENSE_TABLE_NAME="expense";
	public static final String KEY_ID = "id";
	public static final String KEY_SUM = "sum";
	public static final String KEY_CATEGORY = "category";
	public static final String KEY_DATE = "date";
	public static final String KEY_EXPENSE_NAME = "expensename";
	public static String[] allExpenseColumns = { KEY_ID,
			KEY_SUM, KEY_CATEGORY, KEY_DATE, KEY_EXPENSE_NAME };

	public static final String DATABASE_NAME = "Labb2DB";
	public static final int DATABASE_VERSION = 2;

	public static final String DATABASE_CREATE_FIRST = "create table if not exists "+USER_TABLE_NAME+"("+KEY_BUDGET+" integer);";
	public static final String DATABASE_CREATE_SECOND = "create table if not exists "+EXPENSE_TABLE_NAME+"(id integer primary key autoincrement, " +
			KEY_SUM+" integer, "+KEY_CATEGORY+" VARCHAR, "+KEY_DATE+" integer, "+KEY_EXPENSE_NAME+" VARCHAR);";

	DatabaseHelper(Context Context){
		super(Context, DATABASE_NAME, null, DATABASE_VERSION);
	}
	@Override
	public void onCreate(SQLiteDatabase db){
		db.execSQL(DATABASE_CREATE_FIRST);
		db.execSQL(DATABASE_CREATE_SECOND);
	}
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
		db.execSQL("DROP TABLE IF EXISTS user, expense");
		onCreate(db);
	}
}